$.extend(planner.drop.ui, {
    setup_site_menu: function() {
        $( "#mnuDrop" ).menu();

        console.log("setup_site_menu");
        $( "#dnew" ).button();
        $( "#djoin" ).button();
        
        $(".tool").click(function(caller, x) {

            console.log("site_menu: clicked");
            var link    = $(this).attr( "href" );
            var section = $(link);
            
            $(".post").hide();
            
            if (link == "#tutorials")
            {
               $( "#tutorials" ).html( $( "#tutorials" ).comments().html() );
            }
            
            if (link == "#download")
            {
               $( "#download" ).html( $( "#download" ).comments().html() );
            }
            
            $(link).show();
            
            return false;
        });

         
      
      
      
    },
    setup_configure_menu: function() {
        $("#mnuConfigure").menu();
        planner.drop.ui.setup_configure_weapons();
        planner.drop.ui.setup_configure_modules();
        planner.drop.ui.setup_configure_mech();
        planner.drop.ui.setup_configure_speed();
    },
    setup_configure_weapons : function() {
        $("#wstrip").click(function(caller, x) { 
            planner.mech.weapons = [];
            planner.mech.save();
        });
        
        
        handler = function(weapon, count)
        {
            
            return function(caller, x)
            {
                for ( i=0; i < count; i++ )
                    planner.mech.weapons.push( weapon );
                
                planner.mech.save();
                
                return false;
            }
        }
    
        for (j=1; j<5; j++)
        {
            $.each(planner.weapons, function(i, weapon)
            {
                console.log("setup_configure_weapons w " + weapon);
                e = $("#add_weapon_" + weapon + "_" + j);
                w = e.text(); w = w.substring(0,w.length-4)
                e.click( handler(w, j) );
                e.dblclick( handler(w, j) );
            });
        }
    },
    setup_configure_modules : function() {
    
        console.log("setup_configure_modules()");
        $("#estrip").click(function(caller, x) { 
            planner.mech.equipment = [];
            planner.mech.save();
        });
        
        $("#mstrip").click(function(caller, x) { 
            planner.mech.modules = [];
            planner.mech.save();    
        }); 
    
        
        handler = function(caller, x)
        {
            eql = ["BAP", "ECM", "Jumpjets", "Artemis"];
        
            console.log("setup_configure_modules: handler clicked");
            m = $(this).text();

            if ( $.inArray( m, eql) == -1 )
            {
                console.log("setup_configure_modules: handler clicked: add to modules");
                l = planner.mech.modules;    
            }
            else
            {
                console.log("setup_configure_modules: handler clicked: add to eqipment");
                l = planner.mech.equipment;    
            }
            
            if ( $.inArray( m, l) == -1 )
            {
                l.push( m );
                planner.mech.save();
            }
    
            return false;
        }
            
        $.each(planner.modules, function(i, module) {
        
            console.log("setup_configure_modules: module: " + module);
            $("#add_module_" + module).click( handler );
            $("#add_module_" + module).dblclick( handler );
        });
    },
    setup_configure_mech: function()
    {
        $.each(planner.tonnagesGrouped, function(i, list)
        {
            
            c = list[0];
            //console.log("C " + c);
            
            $.each(list[1], function(i, list)
            {
                m = list[0];
                //console.log("M " + m);
                
                $.each(list[1], function(i, item)
                {
                    //console.log("I " + item);
                    id = "#selectmech_" + planner.save_id(m) + planner.save_id(item)
                    //console.log("selectmech" + id);
                    
                    mech = m + "-" + item
                    mech = mech.replace("HERO-", "");
                    
                    handler = function(mech)
                    {
                        return function(caller, x)
                        {
                            // console.log("handler click " + mech);
                            planner.mech.mechtype = mech;
                            planner.mech.save();
                        }
                    }

                    // console.log("handler " + mech);
                    
                    $( id ).click( handler(mech) );
                    
                });
            });
        });
     },
    setup_configure_speed: function()
    {
        for ( i=40; i < 180; i=i+10 ) 
        {    
            handler = function(speed)
            {
                return function() {
                    console.log("setup_configure_speed_handler:clicked()");
                    planner.mech.speed = speed;
                    planner.mech.save();
                }
            }
            
            $("#setspeed_" + i).click( handler(i) );
            $("#setspeed_" + i).dblclick( handler(i) );
        }
    }
});  